home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Tools & Goodies / ODFx / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-26  |  7.3 KB  |  284 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ODFxPrt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "ODFx.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef SELECT_H
  29. #include "Select.h"
  30. #endif
  31.  
  32. // ----- Framework Layer -----
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWITERS_H
  39. #include "FWIters.h"
  40. #endif
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. // ----- OS Layer -----
  47.  
  48. #ifndef FWMENU_H
  49. #include "FWMenu.h"
  50. #endif
  51.  
  52. #ifndef FWCFMRES_H
  53. #include "FWCFMRes.h"
  54. #endif
  55.  
  56. #ifndef FWRESTYP_H
  57. #include "FWResTyp.h"
  58. #endif
  59.  
  60. #ifndef FWSUSINK_H
  61. #include "FWSUSink.h"
  62. #endif
  63.  
  64. #ifndef FWEVENT_H
  65. #include "FWEvent.h"
  66. #endif
  67.  
  68. #ifndef FWBARRAY_H
  69. #include "FWBArray.h"
  70. #endif
  71.  
  72. #ifndef FWABOUT_H
  73. #include "FWAbout.h"
  74. #endif
  75.  
  76. // ----- Foundation Includes -----
  77.  
  78. #ifndef FWSTREAM_H
  79. #include "FWStream.h"
  80. #endif
  81.  
  82. #ifndef FWSTRS_H
  83. #include "FWStrs.h"
  84. #endif
  85.  
  86. #ifndef FWSUSINK_H
  87. #include "FWSUSink.h"
  88. #endif
  89.  
  90. // ----- OpenDoc Includes -----
  91.  
  92. #ifndef SOM_Module_OpenDoc_StdProps_defined
  93. #include <StdProps.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODTranslation_xh
  97. #include <Translt.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODSession_xh
  101. #include <ODSessn.xh>
  102. #endif
  103.  
  104. //========================================================================================
  105. // Constants and Globals
  106. //========================================================================================
  107.  
  108. #define kMainPresentation    "AppleComputer:Presentation:ODFx"
  109.  
  110. //========================================================================================
  111. //    Runtime info
  112. //========================================================================================
  113.  
  114. #ifdef FW_BUILD_MAC
  115. #pragma segment odfx
  116. #endif
  117.  
  118. FW_DEFINE_AUTO(CODFxPart)
  119.  
  120. //========================================================================================
  121. //    CODFxPart class
  122. //========================================================================================
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // CODFxPart constructor
  126. //----------------------------------------------------------------------------------------
  127.  
  128. CODFxPart::CODFxPart(ODPart* odPart) :
  129.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  130.     fPartContent(NULL),
  131.     fPresentation(NULL)
  132. {
  133.     FW_END_CONSTRUCTOR
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // CODFxPart destructor
  138. //----------------------------------------------------------------------------------------
  139.  
  140. CODFxPart::~CODFxPart()
  141. {
  142.     FW_START_DESTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // CODFxPart::Initialize
  147. //----------------------------------------------------------------------------------------
  148.  
  149. void CODFxPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  150. {
  151.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  152.  
  153.     // ----- Register our Presentation
  154.     fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, FW_NEW(CODFxSelection, (ev, fPartContent)));
  155.     
  156.     // ----- Register our other kinds -----
  157.     RegisterKind(ev, 'PICT', kODPlatformDataType, FW_kDataInterchangeStorage/*FW_kAllStorage*/, FW_kExportEnabled);
  158.     RegisterKind(ev, 'PICT', kODPlatformFileType, FW_kFileStorage, FW_kExportEnabled);
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // CODFxPart::NewFrame
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CFrame* CODFxPart::NewFrame(Environment* ev,
  166.                                 ODFrame* odFrame,
  167.                                 FW_CPresentation* presentation,
  168.                                 FW_Boolean fromStorage)    // Override
  169. {
  170.     FW_UNUSED(fromStorage);
  171.  
  172.     return FW_NEW(CODFxFrame, (ev, odFrame, presentation, fPartContent));
  173. }
  174.  
  175. //------------------------------------------------------------------------------
  176. // CODFxPart::NewPartContent
  177. //------------------------------------------------------------------------------
  178.  
  179. FW_CContent* CODFxPart::NewPartContent(Environment* ev)
  180. {
  181.     fPartContent = FW_NEW(CODFxContent, (ev, this));
  182.     return fPartContent;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. // CODFxPart::DoMenu
  187. //----------------------------------------------------------------------------------------
  188.  
  189. FW_Handled CODFxPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  190. {
  191.     FW_Handled menuHandled = FW_kHandled;
  192.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  193.     
  194.     switch (id)
  195.     {
  196.         case c4Colors:
  197.             fPartContent->SetNumColors(ev, CODFxContent::kMinColors);
  198.             break;
  199.             
  200.         case c9Colors:
  201.             fPartContent->SetNumColors(ev, CODFxContent::kMaxColors);
  202.             break;        
  203.  
  204.         case cLowRes:
  205.             fPartContent->SetPixPerRow(ev, CODFxContent::kMinPixPerRow);
  206.             break;        
  207.  
  208.         case cMedRes:
  209.             fPartContent->SetPixPerRow(ev, CODFxContent::kMidPixPerRow);
  210.             break;        
  211.  
  212.         case cHighRes:
  213.             fPartContent->SetPixPerRow(ev, CODFxContent::kMaxPixPerRow);
  214.             break;        
  215.  
  216.         case cRotateColors:
  217.             fPartContent->RotateColors(ev);
  218.             break;        
  219.  
  220.         case cGridLines:
  221.             fPartContent->SetShowGridLines(ev, ! fPartContent->GetShowGridLines());
  222.             break;        
  223.         
  224.         default:
  225.             menuHandled = FW_kNotHandled;
  226.     }
  227.     
  228.     return menuHandled;
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    CODFxPart::DoAbout
  233. //----------------------------------------------------------------------------------------
  234.  
  235. FW_Handled CODFxPart::DoAbout(Environment* ev)
  236. {
  237.     ::FW_About(ev, this, kAbout);
  238.     
  239.     return FW_kHandled;
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. // CODFxPart::DoAdjustMenus
  244. //----------------------------------------------------------------------------------------
  245.  
  246. FW_Handled CODFxPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  247.                                      FW_Boolean hasMenuFocus,
  248.                                      FW_Boolean isRoot)
  249. {
  250. FW_UNUSED(isRoot);
  251.     if (hasMenuFocus)
  252.     {
  253.         // ----- Set up the ODFx menu
  254.         menuBar->EnableAndCheckCommand(ev, c4Colors, TRUE, fPartContent->GetNumColors() == 4);
  255.         menuBar->EnableAndCheckCommand(ev, c9Colors, TRUE, fPartContent->GetNumColors() == 9);
  256.  
  257.         menuBar->EnableAndCheckCommand(ev, cLowRes, TRUE, fPartContent->GetPixPerRow() == CODFxContent::kMinPixPerRow);
  258.         menuBar->EnableAndCheckCommand(ev, cMedRes, TRUE, fPartContent->GetPixPerRow() == CODFxContent::kMidPixPerRow);
  259.         menuBar->EnableAndCheckCommand(ev, cHighRes, TRUE, fPartContent->GetPixPerRow() == CODFxContent::kMaxPixPerRow);
  260.  
  261.         menuBar->EnableAndCheckCommand(ev, cGridLines, TRUE, fPartContent->GetShowGridLines());
  262.  
  263.         menuBar->EnableCommand(ev, cRotateColors, TRUE);
  264.     }
  265.     
  266.     return FW_kNotHandled;
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. // CODFxPart::PartChanged
  271. //----------------------------------------------------------------------------------------
  272.  
  273. void CODFxPart::PartChanged(Environment* ev)
  274. {
  275.     // Mark the document's draft as changed so it can be saved
  276.     this->Changed(ev);
  277.  
  278.     // Mark the display frame as changed, so that containing parts can update links
  279.     fPresentation->ContentUpdated(ev);
  280.  
  281.     // Force all display frames to be redrawn
  282.     fPresentation->Invalidate(ev);
  283. }
  284.